<template>
    <div>
        <div>
            <h1 style="float:left;">企业上市信息</h1>
            <Button @click="handleAdd()" style="color: #fff;background-color: #2d8cf0;border-color: #2d8cf0;margin:0px auto;float:right;">添加</Button>
        </div>
        <div style="padding-top:40px;">
            <AutoTable :columns="columns5" :data="listedCompanyList" :page="page"></AutoTable>
        </div>
        <div>
            <Modal v-model="showModal" width="80%">
                <p slot="header" style="color:#f60;text-align:center">
                    <Icon type="information-circled"></Icon>
                    <span>上市企业详细信息</span>
                </p>
                <div>
                    <CompleteListedCompanyPage  ref="ref1" :listedCompany="listedCompany" @ListenBoardEvent="listenBoard" :Disabled="!is_modify"></CompleteListedCompanyPage>
                </div>
                <div slot="footer" v-if="foot">
                    <div style="text-align:center;">
                        <Button @click="handleSubmit()" style="color: #fff;background-color: #2d8cf0;border-color: #2d8cf0;margin:0px auto;" v-if="is_modify">提交</Button>
                        <Button @click="handleChange()" style="color: #fff;background-color: #2d8cf0;border-color: #2d8cf0;margin:0px auto;" v-if="!is_modify">修改</Button>
                        <Button @click="handleCancel()" style="color: #fff;background-color: #2d8cf0;border-color: #2d8cf0;margin:0px auto;">取消</Button>
                    </div>
                </div>
            </Modal>
        </div>
    </div>
</template>

<script>
import Page from "@/common/model/Page";
import AutoTable from "@/common/components/AutoTable";
import ListedCompany from "@/common/model/ListedCompany";
import CompleteListedCompanyPage from "@/common/components/listed_company_info_page";
export default {
    data() {
        return {
            listedCompany:new ListedCompany(),
            page: new Page("listed_company/getListInfo"), //分页查询接口
            is_modify:false,
            showModal:false,
            foot:true,
            columns5: [
                {
                    type: 'index',
                    title:'序号',
                    width: 80,
                    align: 'center'
                },
                {
                    title: '编号',
                    width: 200,
                    align: 'center',
                    key: 'number'
                },
                {
                    title: '企业名称',
                    align: 'center',
                    key: 'company_name'
                },
                {
                    title: '上市状态',
                    align: 'center',
                    key: 'list_status'
                },
                {
                    title: '板块',
                    align: 'center',
                    key: 'listed_sector'
                },
                {
                    title: '总股本',
                    align: 'center',
                    key: 'total_equity'
                },
                {
                    title:"信息状态",
                    align:"center",
                    width:120,
                    render:(h,params) => {
                        return h('div',[
                            h('Button',{
                                props : { type:["warning","success","error"][params.row.status],size:'small' },
                                style : { marginRight: '5px' }
                            },["未审核","审核通过","审核未通过"][params.row.status])
                        ]);
                    }
                },
                {
                    title:"操作",
                    align:"center",
                    key:"action",
                    width:200,
                    render:(h,params) => {
                        return h('div',[
                            h('Button',{
                                props : { type:'success',size:'small' },
                                style : { marginRight: '5px' },
                                on: { click:() => { this.handleCheckDetial(params.row) } },
                            },'查看详情'),
                            h('Button',{
                                props : { type:'error',size:'small' },
                                style : { marginRight: '5px' },
                                on: { click:() => { this.handalDelete(params.row) } },
                            },'删除')
                        ]);
                    }
                }
            ],
        }
    },
    methods:{
        handleAdd() {
          this.showModal = true;
          this.is_modify = true;
          this.listedCompany = new ListedCompany();
        },
        handleSubmit() {
            this.$refs["ref1"].validate( valid => {
                if(valid) {
                    var url = !this.listedCompany.id?"listed_company/add":"listed_company/change"
                    this.api.post(url,{ listed_company:this.listedCompany.serialize() }, res=>{
                        this.is_modify = false;
                        this.showModal = false;
                        if(res.value){
                            this.page.getData();
                            this.$CustomMessage.success(res.message);
                        }else{
                            this.$CustomMessage.error(res.message);
                        }
                    });                    
                }else {
                    this.$CustomMessage.error(res.message);
                }
            })
        },
        listenBoard(data)
        {
            if(data==="abroad"){
                this.listedCompany.listed_sector ="";
            }
        },
        handleChange(){
            this.is_modify = true;
        },
        handleCancel() {
            this.is_modify = false;
            this.showModal = false;
        },
        handleCheckDetial(row) {
            this.showModal = true;
            this.is_modify = false;
            this.listedCompany = row;
            if(this.listedCompany.status ==="1")
            {
                this.foot = false;
                alert("信息已经通过审核只能查看，不能修改！");
            }else {
                this.foot = true;
            }
        },
        handalDelete(row) {
            if(confirm("是否确认删除？不可恢复！")) {
                this.api.post("listed_company/delete",{id:row.id},res => {
                    if(res.value) {
                        this.page.getData();
                        this.$CustomMessage.success(res.message);
                    }else {
                        this.$CustomMessage.error(res.message)
                    }
                });
            }
        },
    },
    computed:{
        listedCompanyList() {
            return ListedCompany.parseList(this.page.list);
        }
    },
    components: {
        CompleteListedCompanyPage,AutoTable
    }
}
</script>
